<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:if test="survey.surveyId==null"><s:text name="survey.add.title"/></s:if><s:else><s:text name="survey.edit.title"/></s:else></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>

</head>
<body>
<s:set name="siteId" value="#session['CURRENT_SITE'].siteId"></s:set>
<div id="wrapper">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="survey.title"/></div>
	<div class="listtit"><p><span><strong><s:if test="survey.surveyId==null"><s:text name="survey.add.title"/></s:if><s:else><s:text name="survey.edit.title"/></s:else></strong></span></p></div>
	<div class="listadd">
		<s:hidden name="survey.surveyTitle" id="surname"/>
		<s:form action="survey-save" onsubmit="return chkform()">
		<s:hidden name="sflag" id="sflag"/>
		<s:hidden name="survey.surveyId" id="surveyId"/>
		<s:hidden name="optArray" id="optarray"/>
		<s:hidden name="ordArray" id="ordArray"/>
		<s:hidden name="optIdArray" id="optIdArray"/>
		<s:hidden name="soptArray" id="soptArray"/>
		<s:hidden name="checkMArray" id="checkMArray"/>
		<s:hidden name="subjects" id="subjects"/>
		<s:hidden name="vote.site.siteId" id="siteid"/>
		<s:hidden name="checkid" id="checkid"/>
		<s:hidden name="subjectTitle1" id="subjectTitle1"/>
		<s:hidden name="editorsubjects" id="editorsubjects"/>
		<table class="addgrid">
						<tr>
				<th><s:text name="survey.surveyTitle"/>:</th>
				<td><s:textfield id="surveyTitle" name="survey.surveyTitle" maxlength="20" required="true" requiredposition="right" cssClass="txtin" onkeyup="check()"/>
					<span id="point-surveyTitle-Message" style="color: red;">*</span>
					<span id="surveyTitlePointMessage"></span>
				</td>
			</tr>
			<tr>
				<th><s:text name="survey.startTime"/>:</th>
				<%-- <td><sx:datetimepicker name="survey.startTime"  cssClass="txtsearch" displayFormat="yyyy-MM-dd" javascriptTooltip="aasddfasf" /></td> --%>
				<td><input name="survey.startTime" size="30"  class="Wdate" id="qry_startTime_1" readonly="true"  value="<s:date name="survey.startTime" format="yyyy-MM-dd HH:mm:ss"/>"
							onFocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text"/></td>
			</tr>
			<tr>
				<th><s:text name="survey.endTime"/>:</th>
				<%-- <td><sx:datetimepicker name="survey.endTime"  cssClass="txtsearch" displayFormat="yyyy-MM-dd" javascriptTooltip="aasddfasf" /><span id="endtimeno"></span></td> --%>
				<td><input name="survey.endTime" size="30"  class="Wdate" id="qry_startTime_1" readonly="true"  value="<s:date name="survey.endTime" format="yyyy-MM-dd HH:mm:ss"/>"
							onFocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text"/></td>
			</tr>
			<tr>
				<th><s:text name="survey.surveyStatus"/>:</th>
				<td>
					<s:if test="dicSurveyStatus!=null">
						<s:select name="survey.surveyStatus" list="dicSurveyStatus" listKey="dictionaryKey" listValue="dictionaryValue" value="survey.surveyStatus" cssClass="selectClass"/>
					</s:if>
				</td>
				
			</tr>
			<tr>
				<th><s:text name="survey.surveyRepeatSubmitStatus"/>:</th>
				<td>
					<s:if test="dicSurveyRepeatSubmitStatus!=null">
						<s:select name="survey.surveyRepeatSubmitStatus" list="dicSurveyRepeatSubmitStatus" listKey="dictionaryKey" listValue="dictionaryValue" value="survey.surveyRepeatSubmitStatus" cssClass="selectClass"/>
					</s:if>
				</td>
			</tr>
			<tr>
				<th><s:text name="survey.intervalTime"/>:</th>
				<td><s:textfield id="intervaTime" name="survey.intervalTime" maxlength="6" required="true" requiredposition="right" cssClass="txtin" onkeyup="this.value=this.value.replace(/\D/g,'')" onchange="this.value=this.value.replace(/\D/g,'')" />
					<span id="interPointMessage" style="color: red"></span><span style="color: #457d07">(<s:text name="minutes"/>)</span>
				</td>
			</tr>
			<tr>
				<th><s:text name="survey.memo"/>:</th>
				<td><s:textarea name="survey.memo"  cssStyle="height:80px;overflow-y:visible;"  required="true" requiredposition="right" cssClass="txtin"/></td>
			</tr>
			<s:if test="orig.equals(\"edit\")">
			
			<tr>
				<th><s:text name="survey.createTime"/>:</th>
				<td><s:textfield name="survey.createTime" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"><s:param name="value"><s:date name="survey.createTime" format="yyyy-MM-dd HH:mm:ss"/></s:param></s:textfield></td>
			</tr>
			<tr>
				<th><s:text name="survey.createRealName"/>:</th>
				<td><s:textfield name="survey.createRealName" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="survey.createLoginName"/>:</th>
				<td><s:textfield name="survey.createLoginName" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="survey.updateTime"/>:</th>
				<td><s:textfield name="survey.updateTime" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"><s:param name="value"><s:date name="survey.updateTime" format="yyyy-MM-dd HH:mm:ss"/></s:param></s:textfield></td>
			</tr>
			<tr>
				<th><s:text name="survey.updateRealName"/>:</th>
				<td><s:textfield name="survey.updateRealName" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="survey.updateLoginName"/>:</th>
				<td><s:textfield name="survey.updateLoginName" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="survey.joinTotal"/>:</th>
				<td><s:textfield name="survey.joinTotal" required="true" requiredposition="right" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			</s:if>
		<%-- 	<tr>
				<th>&nbsp;</th>
				<td>
					<s:if test="survey.surveyId == null"><s:submit value="%{getText('nextSteps')}" cssClass="btnlist2" onclick="nextVal()"/></s:if>
					<s:submit value="%{getText('save')}" cssClass="btnlist2" onclick="saveSur()"/>
					<s:reset value="%{getText('reset')}" cssClass="btnlist2"/>
					<s:reset value="%{getText('返回')}" cssClass="btnlist2" onclick="goBack()"/>
				</td>
			</tr> --%>
			<tr>
				<s:if test="orig.equals(\"edit\")">
					<th rowspan="2"><s:text name="surveySubject"/>:</th>
					<td><input id="openeditShow" onclick="editaddsub();" type="button" value="<s:text name="addsubject"/>" class="btnlist4" >&nbsp;</td>
				</s:if>
				<s:else>
					<th rowspan="2"><s:text name="surveySubject"/>:</th>
					<td><input id="sursubject"  type="button" value="<s:text name="addsubject"/>" class="btnlist4" >&nbsp;<span style="color: red;">*</span><span id="worn-message"></span></td>
				</s:else>
			</tr>
			<tr>
				<td>
					<ul id="surSubject">
						<s:if test="orig.equals(\"edit\")">
							<s:iterator value="surSubList" status="st">
								<li id="subId<s:property value="#st.index"/>">
									<s:hidden name="subjectId" />
									<s:text name="option"/>:
									<input type="text" value='<s:property value="subjectTitle"/>' name="subjectTitle" id='<s:property value="subjectId"/>_aa' class='button_s05'/>
									<s:text name="ord"/>:
									<s:textfield id="vOrd" name="ord" maxlength="6" required="true" onblur="checkOrd();" requiredposition="right" cssClass="txtin" onkeyup="this.value=this.value.replace(/\D/g,'')" onchange="this.value=this.value.replace(/\D/g,'')"/>
									<a href="#" class="del"><s:text name="delete"/></a>|<a href="javascript:editOption('<s:property value="subjectId"/>')" class="edit" name="edit" id="<s:property value="subjectId"/>"><s:text name="edit"/></a>
									<span id="voteOptPointMessage" style="color: red;"></span>
								</li>
							</s:iterator>
						</s:if>
						<s:else>
							<li id="subId0" style="display: none">
								<s:hidden name="subjectId" />
								<s:text name="option"/>:
								<input type="text" id="fir0" name="subjectTitle" required="true" requiredposition="right" class="txtin" onblur="checkOption();"/>
								<s:text name="优先级"/>:
								<input type="text"  id="sec0" name="ord" maxlength="6" required="true" value="1" requiredposition="right" cssClass="txtin" onblur="checkOrd();" onkeyup="this.value=this.value.replace(/\D/g,'')" onchange="this.value=this.value.replace(/\D/g,'')"/>
								<a href="#" class="del"><s:text name="delete"/></a>|<a href="javascript:editaddOption('sub0')" class="edit" name="edit" id="sub0"><s:text name="edit"/></a>
								<span id="voteOptPointMessage" style="color: red;"></span>
							</li>
						</s:else>
					</ul>
				</td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td>
					<s:if test="%{authLicence('2_2_4',#siteId)}">
						<s:submit value="%{getText('save')}" cssClass="btnlist2" id="infoBtn"/>
					</s:if>
					<s:else>
						<s:submit value="%{getText('save')}" disabled="true" cssClass="btnlist2" />
					</s:else>
					<s:reset value="%{getText('返回')}" cssClass="btnlist2" onclick="goBack()"/>
				</td>
			</tr>
		</table>
		</s:form>
	</div>
</div>
<s:if test="orig.equals(\"edit\")">
<div id="editbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose" class="lightclose" /><strong>维护编辑调查</strong></span></p></div>
	<div class="lightmain">
		<div class="ilghtmainbox2">
			<div class="subtitle">
				<label><span class="red">*</span>科目</label>
				<input id="subTitle" name="subjectTitle" type="text" class="w345" onblur="checkeditTitle();"/><span id="title-message"></span>
				<s:hidden name="subjectId" id="subId"/><br/>
				
			</div>
			
			<s:if test="dicCheckModel!=null">
			<div class="subtitle">
				<s:radio id="checkModel" name="checkModel" list="dicCheckModel" listKey="dictionaryKey" listValue="dictionaryValue"/>
			</div>
			</s:if>
			
			<ul id="subcon" class="subcon">
			
				<li><label><span class="red">*</span>答案1</label><s:hidden name="optionId" id="optionId0"/><input id="optionT0" type="text" name="optionTitle" class="w165" onblur="checkOpt1();"/><br/><span id="answer-message1"></span></li>
				<li><label><span class="red">*</span>答案2</label><s:hidden name="optionId" id="optionId1"/><input id="optionT1" type="text" name="optionTitle" class="w165" onblur="checkOpt2();"/><br/><span id="answer-message2"></span></li>
				<li><label>答案3</label><s:hidden name="optionId" id="optionId2"/><input id="optionT2" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案4</label><s:hidden name="optionId" id="optionId3"/><input id="optionT3" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案5</label><s:hidden name="optionId" id="optionId4"/><input id="optionT4" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案6</label><s:hidden name="optionId" id="optionId5"/><input id="optionT5" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案7</label><s:hidden name="optionId" id="optionId6"/><input id="optionT6" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案8</label><s:hidden name="optionId" id="optionId7"/><input id="optionT7" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案9</label><s:hidden name="optionId" id="optionId8"/><input id="optionT8" name="optionTitle" type="text" class="w165" /></li>
				<li><label>答案10</label><s:hidden name="optionId" id="optionId9"/><input id="optionT9" name="optionTitle" type="text" class="w165" /></li>
			</ul>
			<div class="clear"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="保存" id="lightsubmit" disabled="disabled" onclick="editgetSubject()" class="btnlist2" /><input type="button" id="closebtn" value="关闭"   class="btnlist2" /></div>
	</div>
</div>
</s:if>
<s:else>
	<div id="lightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose" class="lightclose" /><strong>维护新增调查</strong></span></p></div>
	<div class="lightmain">
		<div class="ilghtmainbox2">
			<div class="subtitle">
				<label><span class="red">*</span>科目</label>
				<input id="subjectTitle" name="subTitle" type="text" class="w345"/><span id="title-message"></span><br/>
				<s:if test="dicCheckModel!=null">
							<s:radio id="checkModel" name="checkModel" list="dicCheckModel" listKey="dictionaryKey" listValue="dictionaryValue"/>
				</s:if>
			</div>
			<ul class="subcon">
				<li><label><span class="red">*</span>答案1</label><input id="optionT0" type="text" name="optionTitle" class="w165"/><br/><span id="answer-message1"></span></li>
				<li><label><span class="red">*</span>答案2</label><input id="optionT1" type="text" name="optionTitle" class="w165"/><br/><span id="answer-message2"></span></li>
				<li><label>答案3</label><input name="optionTitle" id="optionT2" type="text" class="w165" /></li>
				<li><label>答案4</label><input name="optionTitle" id="optionT3" type="text" class="w165" /></li>
				<li><label>答案5</label><input name="optionTitle" id="optionT4" type="text" class="w165" /></li>
				<li><label>答案6</label><input name="optionTitle" id="optionT5" type="text" class="w165" /></li>
				<li><label>答案7</label><input name="optionTitle" id="optionT6" type="text" class="w165" /></li>
				<li><label>答案8</label><input name="optionTitle" id="optionT7" type="text" class="w165" /></li>
				<li><label>答案9</label><input name="optionTitle" id="optionT8" type="text" class="w165" /></li>
				<li><label>答案10</label><input name="optionTitle" id="optionT9" type="text" class="w165" /></li>
			</ul>
			<div class="clear"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="保存" id="lightsubmit" onclick="getSubject()" class="btnlist2" /><input type="button" id="closebtn" value="关闭"  class="btnlist2" /></div>
	</div>
</div>
</s:else>
	<script type="text/javascript">
	$("#sursubject").bind("click",function(){
		$$.shade("#sursubject","#lightclose,#closebtn","#lightbox",600);
	 });
	 //$("#sursubject").bind("click",function(){
	//	$$.shadeshowb("lightbox","shadowbox","shadowbox",0,600);
	//	$$.shadehidden("#lightclose,#closebtn","#lightbox");
	// });
	 $("#openeditShow").bind("click",function(){
		$$.shade("#openeditShow","#lightclose,#lightsubmit,#closebtn","#editbox",600);
	 });
	 var arr = $$.g("#surSubject a");
	 for (var i = 0; i < arr.length; i ++){
		 if (arr[i].name == "edit"){
			 var id = arr[i].id;
			 $("#"+arr[i].id).bind("click",function(){
				$$.shade("#"+id+"","#lightclose,#closebtn,#lightsubmit","#editbox",600);
			 });
		 }
	 }
	</script>
	<script type="text/javascript"></script>
</body>
</html>
<script type="text/javascript" defer="defer">
	var surveyId = $("#surveyId").val();
	var checkValue;
	var flag;//在编辑调查中代表是编辑还是新增
	var symbol = false;
	checksymbol=false;
	goDel();
	var isUni="no";
	function chkform(){
		getOption();
		var surveyTitle = $("#surveyTitle").val();
		var surveyT = surveyTitle.replace(/(^\s*)|(\s*$)/g, "");
		var obj = {"survey.surveyTitle":surveyT};	
		if(surveyT == null || surveyT == ""){
			$("#surveyTitlePointMessage").css("color","red");
			$("#surveyTitlePointMessage").html("抱歉 !调查主题不能为空");
			return false;
		}
		if(isUni == "have"){
			return false;
		}
		var starttime=$("input[name=survey.startTime]").val().substr(0,10);
		var endtime=$("input[name=survey.endTime]").val().substr(0,10);
		if(starttime>endtime){
			$("#endtimeno").html("请选择合理的截至日期");
			$("#endtimeno").css("color","red");
			return false;
		}
		var display =  $("#subId0").css("display");
		if(display == 'none'){
			$("#infoBtn").attr("disabled",true);
			$("#worn-message").css("color","red");
			$("#worn-message").html("请添加至少一个调查科目");
			return false;
		}else{
			$("#worn-message").html("");
			$("#infoBtn").attr("disabled",false);
		}
		return checkOption() && checkOrd();
	}
	//输入1秒后检测用户名
	 var timer = false;
   $(function(){
		var surveyTitle = $("#surveyTitle").val();
		if(surveyId != null && surveyId != ""){
			if(surveyTitle==null||surveyTitle==""){
				$("#surveyTitlePointMessage").css("color","#457d07");
				$("#surveyTitlePointMessage").html("不能为空！");
			}else{
				$("#surveyTitlePointMessage").css("color","#457d07");
				$("#surveyTitlePointMessage").html("恭喜!调查主题名称可用");
			}
		}
		var display2 =  $("#subId0").css("display");
		if(display2 == 'none'){
			$("#worn-message").css("color","#457d07");
			$("#worn-message").html("");
		}else{
			$("#worn-message").html("");
		}
		$("#surveyTitle").mouseout(function(){
			var surname = $("#surname").val();
			var surveyTitle = $("#surveyTitle").val();
			var surveyT = surveyTitle.replace(/(^\s*)|(\s*$)/g, "");
			var obj = {"survey.surveyTitle":surveyT,"surname":surname};
			
			if(surveyTitle==null||surveyTitle==""){
				$("#surveyTitlePointMessage").css("color","#457d07");
				$("#surveyTitlePointMessage").html("");
			}else{
				$("#surveyTitlePointMessage").css("color","#457d07");
				$("#surveyTitlePointMessage").html("恭喜!调查主题名称可用");
			}
			
			if(surveyTitle != null && surveyTitle != ""){
				$.post("${ctx}/plugins/survey-checknameunique.action",obj,function(data){
					if(data == "ok"){
						$("#surveyTitlePointMessage").css("color","#457d07");
						$("#surveyTitlePointMessage").html("恭喜!调查主题名称可用");
						isUni="no";
					}else{
						$("#surveyTitlePointMessage").css("color","red");
						$("#surveyTitlePointMessage").html("抱歉!调查主题名称已经被占用，请重新输入");
						isUni="have";
					}
				});
			}
		});
		$("#checkModel0").attr("checked",true);
		$("input[name=checkModel]").change(getCheckModel);
		
	});
   function checkAddOptionT0() {
		 var optionT0=$("#optionT0").val();
		  var optionT0=$.trim(optionT0);	
		  if(optionT0==""||optionT0==null){
				/* $("#answer-message1").css("color","red");
				$("#answer-message1").html("不能为空");	
				$("#lightsubmit").attr("disabled",true); */
				return false;
		  }else{
				/* $("#answer-message1").css("color","red");
				$("#answer-message1").html("");	
				$("#lightsubmit").attr("disabled",false); */
				return true;
		  }
	}
	function checkAddOptionT1() {
		var optionT1=$("#optionT1").val();
		  var optionT1=$.trim(optionT1);
		  if(optionT1==""||optionT1==null){
				/* $("#answer-message2").css("color","red");
				$("#answer-message2").html("不能为空");	
				$("#lightsubmit").attr("disabled",true); */
				return false;
		  }else{
			  /* $("#answer-message2").css("color","red");
				$("#answer-message2").html("");	
				$("#lightsubmit").attr("disabled",false); */
				return true;
		  }
	}
	function goBack(){
		history.go(-1);
	}
	function getOption(){
		var num = $("input[name='subjectTitle']").length;
		var optArray = new  Array(num);
		$("input[name='subjectTitle']").each(function(i){ 
			optArray[i]=$(this).attr("value");
		}); 
		$("#optarray").val(optArray);
		
		var ordArray = new Array();
		$("input[name='ord']").each(function(i){
			ordArray[i]=$(this).attr("value");
		});
		$("#ordArray").val(ordArray);
		
		var bnum = $("#input[name='subjectId']").length;
		var optIdArray = new Array(bnum);
		$("input[name='subjectId']").each(function(i){
			optIdArray[i]=$(this).attr("value");
		});
		$("#optIdArray").val(optIdArray);
	}
	function resetOption(){
			$("input[name='subjectTitle']").val("");
			$("input[name='ord']").val("");
	}
	function goEdit(){
		$(".edit").each(function(index){
			$(this).click(function(){
			});
		});
	}
	//页面删除科目项
	function goDel(){
		$(".del").each(function(index){
			$(this).click(function(){
				var len = $("#surSubject").find("li").length;
				if (len > 1){
					if(surveyId == null || surveyId == ""){
						
					}else{
						del(index);
					} 
					var liId = $(this).parent().attr("id");
					liId = liId.substring(5);
					liId = Number(liId);
					var ar = subjects.split("@");
					ar.splice(liId,1);
					subjects = ar.toString();
					subjects = subjects.replace(/\,/g, '@');
					$("#subjects").val(subjects);
					$(this).parent().remove();
					$("#surSubject").find("li").each(function(i,item){
						$(item).find("input:eq(2)").val(i+1+"");
						$(item).attr("id","subId"+i);
					});
				}else{
					$("#voteOptPointMessage").html("最后一个调查科目不能删除！");
				}
			});
		});
	}
	//数据库删除科目项
	function del(index){
		var bnum = $("#input[name='subjectId']").length;
		var optIdArray = new Array(bnum);
		$("input[name='subjectId']").each(function(i){
			optIdArray[i]=$(this).attr("value");
		});
		obj = {"key":optIdArray[index]};
		if(obj != null){
			if(confirm("确实要删除吗？")){
				$.post("${ctx}/plugins/surveysubject-del.action",obj,function(data){});
			}
		}
	}
	function nextVal(){
		$("#sflag").val("sflag");
	}
	var subjects="";
	function getSubject(){
		var subjectTitle = $("#subjectTitle").val();
		var c0 = checkAddOptionT0();
		var c1 = checkAddOptionT1();
		if(subjectTitle == "" || !c0 || !c1) {
			if(subjectTitle == "") {
				alert("调查科目不能为空！");
				return false;
			}
			if(!c0) {
				alert("答案项1不能为空！");
				return false;
			}
			if(!c1) {
				alert("答案项2不能为空！");
				return false;
			}
		}else {
			$("#lightbox").hide();
			$("#shadowbox").remove();
		}
		if(surveyId == null || surveyId == ""){
			if(!symbol){
				var length=$("#surSubject").find("li").length;//找到ul下面li的个数
				var display =  $("#subId0").css("display");
				if(display == 'none')
				{
					$("#subId0").css("display","block");
					$("#worn-message").html("");
					$("#infoBtn").attr("disabled",false);
				}
				if(display == 'block'){
					var lv = $("#surSubject").find("li:last").find("input:eq(2)").val();
					var lastval = Number(lv);
					$("#surSubject").append($("#surSubject").find("li:eq(0)").clone()); 
					$("#surSubject").find("li:eq("+length+")").attr("id","subId"+length);
					$("#surSubject").find("li:last").find("input:eq(1)").val("");
					$("#surSubject").find("li:last").find("input:eq(2)").val(lastval+1+"");
					$("#surSubject").find("li:last").find("input:eq(1)").attr("id","fir"+lv);
					$("#surSubject").find("li:last").find("input:eq(2)").attr("id","sed"+lv);
					$("#surSubject").find("li:last").find("a:eq(1)").attr("id","sub"+lv);
					$("#surSubject").find("li:last").find("a:eq(1)").attr("href","javascript:editaddOption('sub"+lv+"')");
				}
			}			
			symbol = false;
		}
		goDel();
		if(checksymbol){
			var id=$("input[name=checkid]").val();
			var oldtitle=$("input[name=subjectTitle1]").val();
			var test="fir"+id;
			$("#"+test).val(subjectTitle);
			var ss=$("#"+test).val();
			//得到答案选项标题
			var snum = $("input[name='optionTitle']").length;
			var soptArray = new Array(snum);
			var subject="";
			var sopt="";
			$("input[name=optionTitle]").each(function(i){
				if($(this).val() != ""){
					soptArray[i]=$(this).attr("value");
					sopt = soptArray[i]+"!"+sopt;
				}
			});
			sopt = sopt.substr(0,sopt.length-1);
			subject = subjectTitle+"!"+checkValue+"#"+sopt;
			var newsubjects="";
			var subjecsArray=new Array();
			subjecsArray=subjects.split("@");
			var che=$("input[name=editorsubjects]").val();
			for(var i=0;i<subjecsArray.length;i++){
				if(subjecsArray[i]==che){
				newsubjects=newsubjects+subject+"@";
				}else{
					newsubjects=newsubjects+subjecsArray[i]+"@";
				}
			}
			$("#subjects").val(newsubjects.substr(0,newsubjects.length-1));
			
		}else{
			//var length=$("#surSubject").find("li").length; //找到ul下面li的个数
			//得到调查科目标题
			var subjectTitle = $("#subjectTitle").val();
			$("#surSubject").find("li:last").find("input:eq(1)").val(subjectTitle);
			//$("#surSubject").find("li:last").find("input:eq(2)").val(length);
			//得到答案选项标题
			var snum = $("input[name='optionTitle']").length;
			var soptArray = new Array(snum);
			var subject="";
			var sopt="";	
			$("input[name=optionTitle]").each(function(i){
				if($(this).val() != ""){
					soptArray[i]=$(this).attr("value");
					sopt = soptArray[i]+"!"+sopt;
				}
			});
			sopt = sopt.substr(0,sopt.length-1);
			subject = subjectTitle+"!"+checkValue+"#"+sopt;
			subjects = subjects + subject + "@";
			$("#subjects").val(subjects);
			//添加一个科目后清空 
			$("#subjectTitle").val("");
			$("input[name='optionTitle']").val("");
		}
		
	}
	function editaddsub(){
		flag = 1;
		$("#answer-message1").html("");
		$("#answer-message2").html("");
		$("#subId").val("");
		$("input[name=optionId]").val("");
		$("#subTitle").val("");
		$("input[name='optionTitle']").val("");
	}
	var x = 0;
	function editgetSubject(){
		var length=$("#surSubject").find("li").length;
		if(flag == 1){//代表新增调查项
			var lv = $("#surSubject").find("li:last").find("input:eq(2)").val();
			var lastval = Number(lv);
			$("#surSubject").append($("#surSubject").find("li:eq(0)").clone()); 
			$("#surSubject").find("li:eq("+length+")").attr("id","subId"+length);
			$("#surSubject").find("li:last").find("input:eq(0)").val("");
			$("#surSubject").find("li:last").find("input:eq(1)").val("");
			$("#surSubject").find("li:last").find("input:eq(2)").val(lastval+1+"");
			$("#surSubject").find("li:last").find("a:eq(1)").attr("id","sub"+x);
			$("#surSubject").find("li:last").find("a:eq(1)").attr("href","javascript:editaddOption('sub"+x+"')");
			x++;
		}
		goDel();
		//得到调查科目标题
		//var length=$("#surSubject").find("li").length;
		var subjectTitle = $("#subTitle").val();//科目
		//$("#surSubject").find("li:eq("+(length-1)+") input:eq(1)").val(subjectTitle);
		if(flag == 0){
			var sid = $("#subId").val();
			$("#"+sid+"_aa").val(subjectTitle);
		}else if(flag == 1){
			$("#surSubject").find("li:last").find("input:eq(1)").val(subjectTitle);
		}
		var subId = $("#subId").val();
		
		//得到答案选项标题
		var snum = $("input[name='optionTitle']").length;
		var soptArray = new Array(snum);
		var subject="";
		var sopt="";
		$("input[name=optionTitle]").each(function(i){
		if($(this).val()!=""){
			 soptArray[i]=$(this).attr("value");
			 sopt = soptArray[i]+"!"+sopt;
		 }
		});
		//得到选项ID
		var optId="";
		var optIdnum = $("input[name='optionId']").length;
		var soptIdArray = new Array(optIdnum);
		$("input[name=optionId]").each(function(i){
			if($(this).val()!=""){
				soptIdArray[i]=$(this).attr("value");
				optId = soptIdArray[i]+"!!"+optId;
			 }
			});
		sopt = sopt.substr(0,sopt.length-1);
		if(optId == ""){
			subject = subjectTitle+"!"+checkValue+"#"+sopt;
			subjects = subjects + subject + "@";
		}else {
			subject = subjectTitle+"!"+checkValue+"%"+subId+"#"+sopt+"&"+optId;
			subjects = subjects + subject + "@";
		}
		$("#subjects").val(subjects);
		//添加一个科目后清空
		$("#subTitle").val("");
		$("input[name='optionTitle']").val("");
	}
	function editOption(subId){
		flag = 0;
		$.getJSON("${ctx}/plugins/surveysubject-getSub.action?surveySubject.subjectId="+subId,function(data){
			for(var i=0;i<data.length;i++){
				$("#subTitle").val(data[i].subjectTitle);
				$("#subId").val(data[i].subId);
				$("#checkModel").val(data[i].checkModel);
				if(data[i].checkModel == true){
					$("#checkModel1").attr("checked",true);
				}else{
					$("#checkModel0").attr("checked",true);
				}
			}
		});
		var obj={"surveySubject.subjectId":subId};
		$.getJSON("${ctx}/plugins/subjectoption-getOption.action",obj,function(data){
			for(var i=0;i<data.length;i++){
				$("#optionT"+i).val(data[i].optionTitle);
				$("#optionId"+i).val(data[i].optionId);
			}
		});
	}
	function editaddOption(id_a){
		symbol = true;
		checksymbol=true;
		checkeditor="editor";
		
		var otherid = $("#"+id_a).attr('id');
		if(surveyId == null || surveyId == ""){
			$$.shade("#"+otherid+"","#lightclose,#closebtn,#lightsubmit","#lightbox",600);
		}else{
			$$.shade("#"+otherid+"","#lightclose,#closebtn,#lightsubmit","#editbox",600);
		}
		var strid = $("#"+id_a).attr("id").substring(3);
		var id = Number(strid);
		var array = new Array();
		array = subjects.split("@");
		$("input[name=editorsubjects]").val(array[id]);

		var subjectTitle1 = array[id].substring(0,array[id].indexOf('!'));
		var checkModel1 = array[id].substring(array[id].indexOf('!')+1,array[id].indexOf('#'));
		if(surveyId == null || surveyId == ""){
			$("#subjectTitle").val(subjectTitle1);//科目 
		}else{
			$("#subTitle").val(subjectTitle1);
		}
		$("#checkModel").val(checkModel1);
		var optarr = new Array();
		optarr = array[id].substring(array[id].indexOf('#')+1).split('!');
		for(var i = 0; i < optarr.length; i++){
			$("#optionT"+i).val(optarr[i]);
		}
		$("input[name=checkid]").val(id);
		$("input[name=subjectTitle1]").val(subjectTitle1);
	}
	function getCheckModel(){
		checkValue = $('input[name=checkModel]:checked').val();
	}
	function checkOption(){
		$("#surSubject").find("li").each(function(i,item){
			var option = $(item).children().first().next().val();
			if(option == ""){
				$(item).children().last().css("color","red");
				$(item).children().last().html("调查选项不能为空");
				return false;
			}else {
				$(item).children().last().html("");
				return true;
			}
		});
	}
	function checkOrd(){
		$("#surSubject").find("li").each(function(i,item){
			var ord = $(item).find("input:eq(2)").val();
			if(ord == ""){
				$(item).children().last().css("color","red");
				$(item).children().last().html("优先级序号不能为空");
				$("#infoBtn").attr("disabled",true);
				return false;
			}else{
				$(item).children().last().html("");
				$("#infoBtn").attr("disabled",false);
				return true;
			}
		});
	}
	function checkaddTitle(){
		var titleval = $("input[name=subTitle]").val();
		if(titleval == ""){
			$("#title-message").css("color","red");
			$("#title-message").html("科目不能为空");
			$("#lightsubmit").attr("disabled",true);
			return false;
		}else{
			$("#title-message").html("");
			$("#lightsubmit").attr("disabled",false);
			return true;
		}
	}
	function checkeditTitle(){
		var titleval = $("#subTitle").val();
		if(titleval == ""){
			$("#title-message").css("color","red");
			$("#title-message").html("科目不能为空");
			$("#lightsubmit").attr("disabled",true);
			return false;
		}else{
			$("#title-message").html("");
			$("#lightsubmit").attr("disabled",false);
			return true;
		}
	}
</script>